import 'dart:convert';

import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mes_app/common/index.dart';
import 'package:flutter_mes_app/main.dart';
import 'package:flutter_picker_plus/picker.dart';
import 'package:get/get.dart';

import 'index.dart';

class PickerPage extends GetView<PickerController> {
  const PickerPage({super.key});




  // 主视图
  Widget _buildView(BuildContext context) {
    return <Widget>[
      const TextWidget.h4("基于 flutter_picker_plus 实现").center(),
      Picker(
        adapter: PickerDataAdapter<String>(pickerData: const JsonDecoder().convert(controller.pickerData)),
        itemExtent: 40,
        height: 270,
        backgroundColor: Colors.transparent,
        containerColor: Colors.transparent,
        cancelText: LocaleKeys.commonBottomCancel.tr,
        confirmText: LocaleKeys.commonBottomConfirm.tr,
        onConfirm: (Picker picker, List<int> value) {
          print("picker$picker");
          print("value$value");
        },
      ).makePicker()
    ].toColumnSpace().scrollable().marginOnly(top:50);
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<PickerController>(
      init: PickerController(),
      id: "picker",
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("picker")),
          body: SafeArea(
            child: _buildView(context),
          ),
        );
      },
    );
  }
}
